package de.neusta.android.generic.implementation;

import java.util.List;

import de.neusta.android.entity.Attribute;
import de.neusta.android.generic.Generator;
import de.neusta.android.generic.constants.MethodDeclarationType;
import de.neusta.android.generic.constants.ViewType;
import japa.parser.ASTHelper;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.PackageDeclaration;
import japa.parser.ast.body.ClassOrInterfaceDeclaration;
import japa.parser.ast.body.ModifierSet;

/**
 * Created by dzebcuks on 24.01.14.
 */
public class DefaultGenerator extends AbstractGenerator implements Generator {

    public DefaultGenerator(){
        setCompilationUnit(new CompilationUnit());
    }

    @Override
    public void generate(ViewType viewType) {
        for(Attribute attribute : getAttributes()){
            createFieldDeclaration(attribute);
            createGetter(attribute);
            createSetter(attribute);
        }
    }

    @Override
    public void setClassName(String name) {
        this.className = name;
        ClassOrInterfaceDeclaration type = getClassDeclaration();
        ASTHelper.addTypeDeclaration(getCompilationUnit(), type);
    }

    @Override
    public void setAttributeList(List<Attribute> attributes) {
        this.attributes = attributes;
    }

    @Override
    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
        PackageDeclaration packageDeclaration = new PackageDeclaration(ASTHelper.createNameExpr(getBasePackage()));
        getCompilationUnit().setPackage(packageDeclaration);
    }

}
